/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elsimulatorjava;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * This class is for the SimulationUI
 * It will update all the states for all elevators
 * This panel will be drawn onto the Simulation Tab
 */
public class SimulationPanel extends JPanel implements Runnable {
    private static final int X_GAP = 50, DOOR_WIDTH = 30, DOOR_HEIGHT = 50;
    private ArrayList<Elevator> elevators;
    private ArrayList<Rectangle2D> leftDoor = new ArrayList<Rectangle2D>();
    private ArrayList<Rectangle2D> rightDoor = new ArrayList<Rectangle2D>();
    private ArrayList<Rectangle2D> container = new ArrayList<Rectangle2D>();
    private ArrayList<Integer> yPos;
    
    SimulationPanel(ArrayList<Elevator> e){
        this.elevators = e;
        for (int i = 0; i < e.size(); i++){
            leftDoor.add(new Rectangle(X_GAP+i, e.get(i).getCurrentFloor(), DOOR_WIDTH, DOOR_HEIGHT));
            rightDoor.add(new Rectangle(X_GAP*i+DOOR_WIDTH, e.get(i).getCurrentFloor(), DOOR_WIDTH, DOOR_HEIGHT));
            //draw ((xPos=X_GAP*i), yPox, width, height)
        }
    }
    
    public void run() {
        for (int i = 0; i < elevators.size(); i++){
            // y = elevators.get(i).getCurrentFloor() {{FLOAT VALUE PROBABLY}}
            leftDoor.get(i).setRect(X_GAP+i, elevators.get(i).getCurrentFloor(), DOOR_WIDTH, DOOR_HEIGHT);   
        }
        this.repaint();
    }
    
    @Override
    public void paint(Graphics g){
        super.paint(g);
        Graphics2D g2d = (Graphics2D) g;
        g2d.setPaint(Color.BLACK);
        g2d.setStroke( new BasicStroke( 2.0f ) );
        for (int i = 0; i < leftDoor.size(); i++){
            g2d.draw(leftDoor.get(i));
        }
        
    }
        
}
